package com.moblie.controller;

import com.aliyuncs.exceptions.ClientException;


import com.moblie.constant.MessageConstant;
import com.moblie.constant.RedisMessageConstant;
import com.moblie.entity.Result;
import com.moblie.utils.SMSUtils;
import com.moblie.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

/**
 * 描述:
 * 发送短信
 *
 * @author 景远超
 * @create 2020-05-05 9:45
 */
@RestController
@RequestMapping("/validataCode")
public class validataCodeController {
    @Autowired
    private JedisPool jedisPool;
    @RequestMapping("/send4login")
    public Result sengSMS(String telephone){
        String code = ValidateCodeUtils.generateValidateCode4String(4);
        try {
            SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE,telephone,code);
        } catch (ClientException e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);
        }
        jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_ORDER,5*60,code);
        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);

    }
}
